<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class CoreDelegate {
	var $_type;
	var $_target;
	var $_advice;
	var $_method;
	var $_pointcut;
	
	var $_class_path;
	var $_class_file;
	
	//contructor
	function CoreDelegate() {
		
	}
	
	//setter/getter
	function setTarget($target) {
		$this->_target = $target;
	}
	
	function getTarget() {
		return $this->_target;
	}
	
	function setAdvice($advice) {
		$this->_advice = $advice;
	}
	
	function getAdvice() {
		return $this->_advice;
	}
	
	//methods
	function invoke($obj, $method, $params) {
		if( ($this->_type == 'round' || $this->_type == 'before') ) {
			$advice = $this->_advice;
			if( is_object($this->_advice) ) {
				$advice->doAction();
			} elseif( function_exists($advice) ) {
				$advice();
			}
		}
		//
		$this->_target->$method($params);
		//
		if( ($this->_type == 'round' || $this->_type == 'after') ) {
			$advice = $this->_advice;
			if( is_object($this->_advice) ) {
				$advice->doAction();
			} elseif( function_exists($advice) ) {
				$advice();
			}
		}
	}
	
	//class
	function extend_class() {
		
	}
	
	function include_class() {
		$class_file = $this->_class_file;
		
		include_once($this->_class_path . $this->_class_file);
	}
}
//
?>